<div class="container-fluid" style="margin: 0px 15px 0px 15px;">
<ol class="breadcrumb">
  <li><a href="<?php echo base_url('/index.php/inicio');?>">Início</a></li>
  <li><a href="<?php echo base_url('index.php/inicio/atendimento');?>">Atendimento</a></li>
  <li class="active">Consulta</li>
</ol>
			<fieldset>
				<legend>Consulta Atendimentos</legend>
				<table id="example" class="display responsive nowrap" cellspacing="0" width="100%">
					<thead>
						<tr>
							<th>#</th>
							<th>Data Ligação</th>
							<th>Ramal</th>
							<th>Solicitante</th>
							<th>Telefone</th>
							<th>Solicitado</th>
							<th>Assunto</th>
							<th></th>
							<th>Responsável</th>
						</tr>
					</thead>
					<tbody>
						<?php
							foreach($atendimentos as $atendimento){
								echo '<tr>';
								echo '<td>'.$atendimento->id.'</td>';
								echo '<td>'.$atendimento->dt_cadastro.'</td>';
								echo '<td>'.$atendimento->ramal.'</td>';
								echo '<td>'.$atendimento->solicitante.'</td>';
								echo '<td style="color:blue;font-weight:bold;">'.$atendimento->telefone.'</td>';
								echo '<td style="color:green;font-weight:bold;">'.$atendimento->solicitado.'</td>';
								echo '<td>'.$atendimento->assunto.'</td>';
								
								echo '<td>';
								if($atendimento->status != null){
									echo '<a style="margin-right:5px;width:103px;" data-toggle="modal" href="#" class="btn btn-danger btn-xs">Finalizado</a>';
									//echo '<a data-toggle="modal" href="'.base_url('index.php/inicio/ligardenovo/'.$atendimento->id).'" class="btn btn-success btn-xs"><span class="glyphicon glyphicon-refresh"></span> Ligar novamente</a>';
									echo '<a data-toggle="modal" href="#" onclick="atenderNovamente('.$atendimento->id.');" class="btn btn-success btn-xs"><span class="glyphicon glyphicon-refresh"></span> Ligar novamente</a>';
								}else{
									echo '<a data-toggle="modal" href="#" class="btn btn-warning btn-xs">Em atendimento</a>';
								}
								echo'</td>';
								echo '<td>'.$atendimento->nome_completo.'</td>';
								echo ' </tr>';

							}
						?>	  
					
					</tbody>
				</table>
				
				
			</div>
			</fieldset>
<?php
/* echo '<pre>';
print_r($this->session->all_userdata());
echo '</pre>'; */

?>		
		<script type="text/javascript">
			$(document).ready(function(){
				var table = $('#example').DataTable({
					"order": [[ 0, "desc" ]],
					"language": {
						"url": "<?php echo base_url('includes/js/Portuguese-Brasil.json'); ?>"
					},
					 "pagingType": "simple"
				});
			
			
				$('#example tbody').on( 'click', 'tr', function () {
					if ( $(this).hasClass('selected') ) {
						$(this).removeClass('selected');
					}
					else {
						table.$('tr.selected').removeClass('selected');
						$(this).addClass('selected');
					}
				} );
			});
			function atenderNovamente(id){
			
				$.ajax({  
					type: "POST",  
					url: "<?php echo base_url('index.php/inicio/ligardenovo/');?>" +'/'+ id,  
					data: "dados="+id,  
					success: function( data )  
					{  
						//alertify.alert( data );
						alert( data );
						window.location = "<?php echo base_url('index.php/inicio/atendimento');?>";
					}  
				});  
				return false;
			
			}
			
		</script>
</body>
</html>
